import 'package:flutter/material.dart';
import 'package:jd_flutter/base/foundation/flutter_extension.dart';
import 'package:jd_flutter/base/utils/jd_log.dart';
import 'package:jd_flutter/base/widget/image/jd_asset_image.dart';
import 'package:jd_flutter/base/widget/image/jd_network_image.dart';
import 'package:jd_flutter/modules/pages/home/models/home_model.dart';
import 'package:jd_flutter/modules/pages/home/widgets/home_header_widget.dart';
import 'package:jd_flutter/modules/pages/home/widgets/home_list_bottom_widget.dart';
import 'package:jd_flutter/modules/pages/home/widgets/text_more_widget.dart';
import 'package:jd_flutter/modules/router/router_contract_page.dart';

class HomeLeftScrollWidget extends StatelessWidget {
  final HomeModel? homeModel;
  const HomeLeftScrollWidget({super.key, this.homeModel});

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        10.vGap,
        const HomeHeaderWidget(),
        TextMoreWidget(
          homeModel: homeModel,
        ),
        10.vGap,
        Container(
          margin: const EdgeInsets.all(10),
          height: 100,
          clipBehavior: Clip.hardEdge,
          decoration: const BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(15)),
          ),
          child: Row(
            children: [
              SizedBox(
                width: (context.width - 30) / 2 - 10,
                height: double.infinity,
                child: const JDAssetImage(
                  'eat_new_orleans_sm.png',
                  fit: BoxFit.cover,
                ),
              ),
              9.hGap,
              Column(
                children: [
                  Container(
                    alignment: Alignment.center,
                    width: (context.width - 30) / 2 - 1,
                    height: 30,
                    color: Colors.white,
                    child: InkWell(
                      child: const Text(
                        '数据库demo',
                        style: TextStyle(fontSize: 13),
                      ),
                      onTap: () {
                        RouterContractPage.instance.dBDemoPage.push(context);
                      },
                    ),
                  ),
                  5.vGap,
                  GestureDetector(
                    onTap: () {},
                    child: SizedBox(
                      width: (context.width - 30) / 2 - 1,
                      height: 65,
                      child: const JDAssetImage(
                        'eat_cape_town_sm.png',
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                ],
              )
            ],
          ),
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Padding(
              padding: EdgeInsets.fromLTRB(14, 20, 12, 0),
              child: Text(
                '今日推荐',
                style: TextStyle(
                    color: Color(0xFF222222),
                    fontSize: 16,
                    fontWeight: FontWeight.w600),
              ),
            ),
            ListView.builder(
              itemCount: 5,
              physics: const NeverScrollableScrollPhysics(),
              padding: const EdgeInsets.only(top: 10.0),
              shrinkWrap: true,
              itemBuilder: (context, index) {
                return Row(
                  children: [
                    10.hGap,
                    JDNetworkImage(
                      url: getRandomImageUrl(),
                      width: 40,
                      height: 40,
                      borderRadius: const BorderRadius.all(Radius.circular(3)),
                    ),
                    10.hGap,
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('当前是第${index + 1}行',
                            style: const TextStyle(
                                fontSize: 13, fontWeight: FontWeight.normal)),
                        5.vGap,
                        Container(
                          constraints:
                              BoxConstraints(maxWidth: context.width - 80),
                          child: Text(
                            '我一定要成为flutter高手我一定要成为flutter高手我一定要成为flutter高手我一定要成为flutter高手',
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                                color: Colors.blue.withOpacity(0.8),
                                fontSize: 13,
                                fontWeight: FontWeight.normal),
                          ),
                        )
                      ],
                    ),
                    10.hGap,
                  ],
                );
              },
            ),
            10.vGap,
            const Padding(
              padding: EdgeInsets.fromLTRB(14, 20, 12, 0),
              child: Text(
                '精彩故事',
                style: TextStyle(
                    color: Color(0xFF222222),
                    fontSize: 16,
                    fontWeight: FontWeight.w600),
              ),
            ),
            GridView.builder(
                physics: const NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
                scrollDirection: Axis.vertical,
                itemCount: 4,
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    childAspectRatio: 174.0 / 295.0,
                    crossAxisCount: 2,
                    mainAxisSpacing: 8,
                    crossAxisSpacing: 7),
                itemBuilder: (BuildContext context, int index) {
                  return GestureDetector(
                    onTap: () {
                      jdLog('点击');
                    },
                    child: Container(
                      clipBehavior: Clip.hardEdge,
                      decoration: const BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10)),
                      ),
                      child: Column(
                        children: [
                          const Expanded(
                              child: JDNetworkImage(
                            url: testUrl,
                          )),
                          Container(
                            height: 71,
                            width: double.infinity,
                            padding: const EdgeInsets.fromLTRB(8, 10, 8, 10),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                const Text(
                                  '我是一个flutter开发者',
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: Color(0xFF222222),
                                      fontSize: 14,
                                      fontWeight: FontWeight.w600),
                                ),
                                10.vGap,
                                const HomeBottomWidget(
                                  urlList: [
                                    testUrl,
                                    'https://upload-images.jianshu.io/upload_images/25564814-13bbc0f01ba5e9ea.jpg',
                                    'https://upload-images.jianshu.io/upload_images/25564814-45d904e388cf040a.jpg'
                                  ],
                                  count: '12344',
                                )
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  );
                }),
            20.vGap,
            20.vGap,
          ],
        ),
      ],
    );
  }
}
